#define _CRT_SECURE_NO_WARNINGS 1
#include"queue.h"
void QueueInit(queue* pq)
{
	assert(pq);
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
void QueuePush(queue* pq, Qdata x)
{
	assert(pq);
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	if (newnode == NULL)
	{
		perror("newnode creat fail");
	}
	newnode->next = NULL;
	newnode->val = x;
	if (pq->ptail == NULL)
	{
		pq->ptail = pq->phead = newnode;
	}
	else
	{
		pq->ptail->next = newnode;
		pq->ptail = newnode;
	}
	pq->size++;
}
void QueuePop(queue* pq)
{
	assert(pq);
	assert(pq->phead);
	QNode* del = pq->phead;
	pq->phead = pq->phead->next;
	free(del);
	if (pq->phead == NULL)
		pq->ptail = NULL;
	pq->size--;
}
Qdata QueueFront(queue* pq)
{
	assert(pq);
	assert(pq->phead);
	return 	 pq->phead->val;

}
QueueBack(queue* pq)
{
	assert(pq);
	assert(pq->phead);
	return	 pq->ptail->val;
}
bool QueueEmpty(queue* pq)
{
	assert(pq);

	return pq->phead == NULL;
}
int QueueSize(queue* pq)
{
	assert(pq);
	return pq->size;
}
void QueueDestroy(queue* pq)
{
	assert(pq);
	QNode* del = pq->phead;
	while (del)
	{
		QNode* next = del->next;
		free(del);
		del = next;
	}
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
